package dymnd.plugin;

import java.awt.*;
import java.awt.geom.*;
import java.awt.image.*;

import dymnd.image.Layer;
public class BasicUtils {
	
	
	/**
	 * A utility method for clearing a line of n*2 thickness
	 * 
	 * @param layer - A layer item, this is where the line will be cleared from
	 * @param startX - The starting X coordinate
	 * @param startY - The starting Y coordinate
	 * @param endX - The ending X coordinate
	 * @param endY - The ending Y coordinate
	 * @param radius - The radius of the line
	 */
	//This method contributed to by snail
	//Thanks snail! Your math RAWKS! 
	
	//Two optimization issues: Make multi-threaded
	// Analyzes way too much on perfectly diagonal lines
	/*public static void clearLine(Layer layer, int startX,int startY, int endX,int endY,int radius){
		
		
		Line2D.Double line = new Line2D.Double(startX,startY,endX,endY);
		int left  = Math.min(startX,endX)-radius;
		int right = Math.max(startX,endX)+radius;
		int top   = Math.min(startY,endY)-radius;
		int bottom= Math.max(startY,endY)+radius;
		if(left<0) left=0;
		if(right>=layergetWidth()) right=layer.buffer.getWidth();
		if(top<0) top=0;
		if(bottom>=layer.buffer.getHeight()) bottom=layer.buffer.getHeight();
		
				
		//Area lineArea = new Area();
		
		for(int x = left; x <= right ; x++)
			for(int y = top; y <= bottom ; y++)	{
				if(line.ptSegDist(x, y)<=radius)	{
					if(x >= 0 && x < layer.buffer.getWidth() && y >= 0 && y < layer.buffer.getHeight()) {//make sure we don't draw outside of coordinate space
						layer.buffer.setRGB(x, y, 0x0);
					}	
				}
			}
	}*/
	
	
	/*public static void drawLine(Layer layer, int startX,int startY, int endX,int endY,int radius, Color c){
		
		
		Line2D.Double line = new Line2D.Double(startX,startY,endX,endY);
		int left  = Math.min(startX,endX)-radius;
		int right = Math.max(startX,endX)+radius;
		int top   = Math.min(startY,endY)-radius;
		int bottom= Math.max(startY,endY)+radius;
		if(left<0) left=0;
		if(right>=layer.buffer.getWidth()) right=0;
		if(top<0) top=0;
		if(bottom>=layer.buffer.getHeight()) bottom=layer.buffer.getHeight();
		
				
		//Area lineArea = new Area();
	
		Graphics2D g = layer.buffer.createGraphics();
		g.setColor(c);
		for(int x = left; x <= right ; x++)
			for(int y = top; y <= bottom ; y++)	{
				if(line.ptSegDist(x, y)<=radius)	{
					if(x >= 0 && x < layer.buffer.getWidth() && y >= 0 && y < layer.buffer.getHeight()) {//make sure we don't draw outside of coordinate space
							g.drawLine(x, y, x, y);					}	
				}
			}
	}*/
	
	/*public static Area calculateLineArea(int startX,int startY, int endX,int endY,int radius)	{
		Line2D.Double line = new Line2D.Double(startX,startY,endX,endY);
		int left  = Math.min(startX,endX)-radius;
		int right = Math.max(startX,endX)+radius;
		int top   = Math.min(startY,endY)-radius;
		int bottom= Math.max(startY,endY)+radius;
			
		Area a = new Area();
		for(int x = left; x <= right ; x++)
			for(int y = top; y <= bottom ; y++)
				if(line.ptSegDist(x, y)<=radius)
					a.add(new Area(new Rectangle2D.Double(x, y, 1, 1)));
		return a;
	}*/
	
	/*public void expDrawLine(int startX, int startY, int endX, int endY, Layer l, int rad)	{
		
		
	}*/
	
	
	/*public static int createHash(String s)	{
		int hash = 33;
		char[] chars = s.toCharArray();
		for(int i = 0; i < chars.length; i++)	{
			hash += hash+chars[i];
		}
		return hash;
	}*/
	
}
